/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package manager.modulo.ordemservico.fonte;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedList;
import manager.auxiliares.Configurations;
import manager.auxiliares.DateConverter;
import manager.modulo.ordemservico.enumerator.EnumSituacaoOrdemServico;
import manager.modulo.ordemservico.enumerator.EnumSituacaoOrdemServico.SituacaoOS;
import manager.principal.fonte.JanelaLogin;

/**
 *
 * @author THIAGO
 */
public class JanelaFiltroOrdemServico extends javax.swing.JFrame {

    /**
     * Creates new form JanelaFiltroOrdemServico
     */
    public JanelaFiltroOrdemServico() {
        this.setIconImage(JanelaLogin.icon);
        initComponents();

        configureWindow();
    }

    private void configureWindow() {
        LinkedList<SituacaoOS> listaSituacao = EnumSituacaoOrdemServico.ListaSituacao();
        for (int i = 0; i < listaSituacao.size(); i++) {
            jComboBox7.addItem(EnumSituacaoOrdemServico.ConvertEnumString(listaSituacao.get(i)));
        }

        Calendar dataAtual = Calendar.getInstance();
        dataAtual.setTimeInMillis(DateConverter.getDataAtualBancoDados().getTime());
        jComboBox2.setSelectedIndex(dataAtual.get(Calendar.MONTH));
        jComboBox5.setSelectedIndex(dataAtual.get(Calendar.MONTH));
        jComboBox3.setSelectedItem(Integer.toString(dataAtual.get(Calendar.YEAR)));
        jComboBox4.setSelectedItem(Integer.toString(dataAtual.get(Calendar.YEAR)));
    }

    public boolean temFiltroHabilitado() {
        if (jCheckBox1.isSelected() || jCheckBox2.isSelected()) {
            return true;
        }
        return false;
    }

    public HashMap<String, Object> getFiltros() {
        HashMap<String, Object> filtros = new HashMap<String, Object>();
        if (jCheckBox1.isSelected()) {
            Timestamp dataInicio = new Timestamp(Integer.parseInt(jComboBox3.getSelectedItem().toString()) - 1900, jComboBox2.getSelectedIndex(), Integer.parseInt(jComboBox1.getSelectedItem().toString()), 0, 0, 0, 0);
            filtros.put("dataInicio", dataInicio);

            Timestamp dataFim = new Timestamp(Integer.parseInt(jComboBox4.getSelectedItem().toString()) - 1900, jComboBox5.getSelectedIndex(), Integer.parseInt(jComboBox6.getSelectedItem().toString()), 23, 59, 59, 0);
            filtros.put("dataFim", dataFim);
        }
        if (jCheckBox2.isSelected()) {
            filtros.put("situacao", Integer.toString(EnumSituacaoOrdemServico.ConverterEnumNumero(EnumSituacaoOrdemServico.ConvertStringEnum(jComboBox7.getSelectedItem().toString()))));
        }
        return filtros;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        jComboBox4 = new javax.swing.JComboBox();
        jComboBox5 = new javax.swing.JComboBox();
        jComboBox6 = new javax.swing.JComboBox();
        jPanel4 = new javax.swing.JPanel();
        jCheckBox2 = new javax.swing.JCheckBox();
        jComboBox7 = new javax.swing.JComboBox();

        setTitle("Filtro de Ordem de Serviço");
        setResizable(false);

        jPanel1.setBackground(Configurations.getBackGroundColor());

        jPanel2.setBackground(Configurations.getBackGroundColor());
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel2.setLayout(null);

        jCheckBox1.setBackground(Configurations.getBackGroundColor());
        jCheckBox1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jCheckBox1.setText("Data de Cad. :");
        jCheckBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCheckBox1ItemStateChanged(evt);
            }
        });
        jPanel2.add(jCheckBox1);
        jCheckBox1.setBounds(10, 20, 110, 23);

        jLabel1.setText("Início");
        jPanel2.add(jLabel1);
        jLabel1.setBounds(170, 5, 25, 14);

        jLabel2.setText("Fim");
        jPanel2.add(jLabel2);
        jLabel2.setBounds(320, 5, 16, 14);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        jComboBox1.setEnabled(false);
        jPanel2.add(jComboBox1);
        jComboBox1.setBounds(130, 20, 37, 20);

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        jComboBox2.setEnabled(false);
        jPanel2.add(jComboBox2);
        jComboBox2.setBounds(170, 20, 37, 20);

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2011", "2012", "2013", "2014", "2015" }));
        jComboBox3.setEnabled(false);
        jPanel2.add(jComboBox3);
        jComboBox3.setBounds(210, 20, 50, 20);

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2011", "2012", "2013", "2014", "2015" }));
        jComboBox4.setEnabled(false);
        jPanel2.add(jComboBox4);
        jComboBox4.setBounds(350, 20, 50, 20);

        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        jComboBox5.setEnabled(false);
        jPanel2.add(jComboBox5);
        jComboBox5.setBounds(310, 20, 37, 20);

        jComboBox6.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        jComboBox6.setSelectedIndex(30);
        jComboBox6.setEnabled(false);
        jPanel2.add(jComboBox6);
        jComboBox6.setBounds(270, 20, 37, 20);

        jPanel4.setBackground(Configurations.getBackGroundColor());
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel4.setLayout(null);

        jCheckBox2.setBackground(Configurations.getBackGroundColor());
        jCheckBox2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jCheckBox2.setText("Situação :");
        jCheckBox2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCheckBox2ItemStateChanged(evt);
            }
        });
        jPanel4.add(jCheckBox2);
        jCheckBox2.setBounds(10, 20, 110, 23);

        jComboBox7.setEnabled(false);
        jPanel4.add(jComboBox7);
        jComboBox7.setBounds(130, 20, 270, 20);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCheckBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCheckBox1ItemStateChanged
        if (jCheckBox1.isSelected()) {
            jComboBox1.setEnabled(true);
            jComboBox2.setEnabled(true);
            jComboBox3.setEnabled(true);
            jComboBox4.setEnabled(true);
            jComboBox5.setEnabled(true);
            jComboBox6.setEnabled(true);
        } else {
            jComboBox1.setEnabled(false);
            jComboBox2.setEnabled(false);
            jComboBox3.setEnabled(false);
            jComboBox4.setEnabled(false);
            jComboBox5.setEnabled(false);
            jComboBox6.setEnabled(false);
        }
    }//GEN-LAST:event_jCheckBox1ItemStateChanged

    private void jCheckBox2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCheckBox2ItemStateChanged
        if (jCheckBox2.isSelected()) {
            jComboBox7.setEnabled(true);
        } else {
            jComboBox7.setEnabled(false);
        }
    }//GEN-LAST:event_jCheckBox2ItemStateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JComboBox jComboBox6;
    private javax.swing.JComboBox jComboBox7;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    // End of variables declaration//GEN-END:variables
}
